# coding=utf-8
import tushare as ts
import json
import peewee
import os
from models import Index, Flag
from sqlalchemy import create_engine

engine = create_engine('sqlite:///data.sqlite')

ts.set_token('b46ae864716dbb76999f35738dcd531a8eab6809740045dd78b8ceba')
pro = ts.pro_api()

markets = ['MSCI', 'CSI', 'SSE', 'SZSE', 'CICC', 'SW', 'CNI', 'OTH']

# for m in markets:
#     print 'm', m
#     df = pro.index_basic(market=m)
#     df.to_sql('index', con=engine, if_exists='append', index=False)

# ts.get_today_all()

# print ts.get_h_data('39
# 9106', index=True, start='2015-01-01', end='2015-03-16')


indexes = [
    '000300.SH',  # 300
    '000905.SH',  # 500
    '000016.SH',  # 50
    '399006.SZ',  # 创业板
    '000990.SH',  # 全指消费
    '000807.SH',  # 食品饮料
    '000993.SH',  # 全指信息
    'h11136.CSI', # 中国互联
]
for idx in indexes:
    idx_info = Index.select().where(Index.ts_code == idx)[0]
    print idx_info
# pro.daily_basic(ts_code='', trade_date='20080726')
# print pro.query('daily_basic', ts_code='801002', trade_date='20180721', fields='pe,pb,ts_code,close')

# print pro.index_basic(market='SW')
# print pro.index_basic(market='CSI')
# df = pro.index_weight(index_code='399300.SZ', trade_date='20180903')

# print df.to_json()
